package com.candy.control;

import com.candy.dao.DBHelper;
import com.candy.modal.UserLoginModal;
import com.candy.pojo.users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UserLogin")
public class UserLogin extends HttpServlet {
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String userName= request.getParameter("userName");
        String userPwd= request.getParameter("userPwd");
        System.out.println("登录的用户名："+userName+"，登录的密码："+userPwd);
        UserLoginModal userM=new UserLoginModal();
        String strSql="select * from users where uid='"+userName+"' and pwd='"+userPwd+"'";
        boolean isok=userM.isLogined(strSql);
        if(isok){
            request.getSession().setAttribute("loginedName",userName);
            System.out.println("登录成功");
            request.getRequestDispatcher("logined.jsp").forward(request,response);
        }else {
            response.sendRedirect("login.jsp");
        }

    }


}
